package cn.tedu.luban.worker.main.repository;

import cn.tedu.luban.worker.main.converter.WorkerCategoryConverter;
import cn.tedu.luban.worker.main.mapper.WorkerCategoryMapper;
import cn.tedu.luban.worker.protocol.bo.WorkerCategoryBO;
import cn.tedu.luban.worker.protocol.dos.WorkerCategoryDO;
import cn.tedu.luban.worker.protocol.param.WorkerRegistParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class WorkerCategoryRepoImpl implements WorkerCategoryRepository {

    @Autowired(required = false)
    private WorkerCategoryMapper workerCategoryMapper;

    @Autowired
    private WorkerCategoryConverter workerCategoryConverter;

    @Override
    public void deleteByUserId(Long userId) {
        workerCategoryMapper.deleteByUserId(userId);
    }

    @Override
    public void saveWorkerCategories(WorkerRegistParam param) {

        // 对象的转换 param -> do
        List<WorkerCategoryDO> dos = workerCategoryConverter.params2dos(param.getWorkerRegistCategoryParams(),param.getUserId());

        // 批量新增
        workerCategoryMapper.batchInsert(dos);

    }

    @Override
    public List<WorkerCategoryBO> findCategories(Long userId) {
        List<WorkerCategoryDO> dos = workerCategoryMapper.selectByUserId(userId);
        return workerCategoryConverter.dos2bos(dos);
    }
}
